//
//  YearPickVIew.m
//  WULIHH
//
//  Created by Gamefire on 16/5/3.
//  Copyright © 2016年 tang. All rights reserved.
//

#import "YearPickVIew.h"
@interface YearPickVIew ()<UIPickerViewDelegate>
{

    NSString *string;
    NSMutableArray *array;
    
}

@end

@implementation YearPickVIew

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self initUI];
    
    }
    return self;
}


- (void)initUI{
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 50)];
//    [topView setBackgroundColor:[UIColor orangeColor]];
    [self addSubview:topView];
    
    
    UIPickerView *pickView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, self.bounds.size.height)];
//    [pickView setBackgroundColor:[UIColor redColor]];
    [pickView setDelegate:self];
    [self addSubview:pickView];
    array = [NSMutableArray array];
    
    for (int i = 1; i <= 100; i++) {
        string = [NSString stringWithFormat:@"%d",i];
        [array addObject:string];
    }
    
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    //    [leftButton setBackgroundColor:[UIColor blackColor]];
    [leftButton setTitle:@"取消" forState:UIControlStateNormal];
    [leftButton.titleLabel setFont:[UIFont systemFontOfSize:14.0]];
    [leftButton addTarget:self action:@selector(leftClearEvent:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self addSubview:leftButton];
    
    UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 50, 0, 50, 50)];
    //    [rightButton setBackgroundColor:[UIColor yellowColor]];
    [rightButton setTitle:@"确定" forState:UIControlStateNormal];
    [rightButton.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
    //    [rightButton setBackgroundColor:[UIColor blackColor]];
    [rightButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(rightDetermineEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:rightButton];

}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{

    return 1;

}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

    return 100;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    
    _age = array[row];
    
    return _age;
}

-(void)leftClearEvent:(UIButton *)sender{
    
    [UIView animateWithDuration:0.3 animations:^{
        CGRect frame;
        frame = self.frame;
        CGFloat delta = frame.origin.y;
        frame.origin.y = MAX([UIScreen mainScreen].bounds.size.height, frame.origin.y - delta);
        self.frame = frame;
    }];
    
   
    

}
- (void)rightDetermineEvent:(UIButton *)sender{
    
    [UIView animateWithDuration:0.3 animations:^{
        CGRect frame;
        frame = self.frame;
        CGFloat delta = frame.origin.y;
        frame.origin.y = MAX([UIScreen mainScreen].bounds.size.height, frame.origin.y - delta);
        self.frame = frame;
    }];
    if (_delegate && [_delegate respondsToSelector:@selector(TouchEvent:)]) {
        [_delegate TouchEvent:sender];
    }
}
@end
